<?php

namespace app\admin\controller;

use app\common\business\AdminRole;
use app\common\lib\Param;
use app\common\lib\Show;
use think\response\Json;

class Aboutus extends AdminBase
{

    public function getData(): Json
    {

        try {
            $info = (new \app\common\business\Aboutus())->getNormalById(1);
        }catch (\Exception $e){
            return Show::error([], $e->getMessage(), $e->getCode());
        }
        return Show::success($info);
    }

    /**
     * 新增/保存数据
     * @return Json
     */
    public function setData(): Json
    {
        list($id, $content) = Param::postMore([
            ['id',0],
            ['content', ''],
        ], $this->request, true);

        $data=[
            'id'=>$id,
            'content'=>$content,
        ];
        $validate = new \app\admin\validate\Aboutus();
        if (!$validate->check($data)) {
            return Show::error([], $validate->getError());
        }

        try {
            $result = (new \app\common\business\Aboutus())->save($data);
        } catch (\Exception $e) {
            return Show::error([], $e->getMessage(), $e->getCode());
        }

        if ($result) {
            return Show::success([], "保存成功");
        }
        return Show::error([], '保存失败');
    }
}
